
import 'package:flutter/material.dart';

class HomePage extends StatelessWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('cy工具大合集'),
        leading: const Icon(Icons.pan_tool),
      ),
      body: GridView.count(
        padding: const EdgeInsets.all(20),
        primary: false,
        crossAxisSpacing: 20,
        mainAxisSpacing: 20,
        crossAxisCount: _getCrossAxisCount(context),
        children: _toolItems(),
      ),
    );
  }

  List<Widget> _toolItems() {
    List<Widget> list = [];
    for (int i = 0; i < 30; i++) {
      list.add(
        Container(
          width: 100,
          height: 100,
          decoration: const BoxDecoration(
              color: Colors.blue
          ),
        ));
    }
    return list;
  }

  int _getCrossAxisCount(BuildContext context) {
    final size = MediaQuery.of(context).size;
    final ratio = size.aspectRatio;
    if (ratio > 1) {
      if (size.width >= 1000) {
        return 8;
      }
      return 6;
    }
    return 2;
  }
}
